package com.liuyucheng.idea_springboot.controller;

import com.liuyucheng.idea_springboot.bean.Result;
import com.liuyucheng.idea_springboot.bean.SwaggerUser;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/swagger")
public class TestSwaggerController {

    /**
     * 测试Swagger的api文档功能（这个注释并不能被swagger解析，需要使用注解来注释接口）
     * 接口文档实时更新
     * 可以在网页上进行接口调试，作用类似于Postman
     * 最好在开发环境开启，生产环境关闭
     * @param request 请求request
     * @param user 用户
     * @return 新的用户
     */
    @ApiOperation(value = "swagger功能测试",notes = "swagger功能测试")
    @PostMapping("/testPost")
    public Result<SwaggerUser> test(HttpServletRequest request, SwaggerUser user) {
        System.out.println("user = " + user);
        System.out.println("request = " + request);
        return Result.data(new SwaggerUser());
    }

    @ApiOperation(value = "swagger功能测试",notes = "swagger功能测试")
    @GetMapping("/testGet")
    public Result<SwaggerUser> testGet(HttpServletRequest request, SwaggerUser user) {
        System.out.println("user = " + user);
        System.out.println("request = " + request);
        return Result.data(new SwaggerUser());
    }

}
